package com.neuedu.elmserver.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.neuedu.elmserver.mapper.BusinessMapper;
import com.neuedu.elmserver.mapper.FoodMapper;
import com.neuedu.elmserver.pojo.Business;
import com.neuedu.elmserver.pojo.Food;
import com.neuedu.elmserver.service.FoodService;
import com.neuedu.elmserver.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;


/**
 * <p>
 * 食品表 服务实现类
 * </p>
 *
 * @author wyh
 * @since 2024-11-07
 */
@Service
public class FoodServiceImpl extends ServiceImpl<FoodMapper, Food> implements FoodService {

    @Autowired
    private FoodMapper foodMapper;

    @Autowired
    private BusinessMapper businessMapper;

    /**
     * 根据商家编号查询食品列表
     * @param businessId
     * @return
     */
    @Override
    public ResultVO queryFoodByBusiness(Integer businessId) {
        QueryWrapper qw=new QueryWrapper();
        qw.eq("business_id",businessId);
        return ResultVO.ok("查询成功", foodMapper.selectList(qw));
    }

    @Override
    public ResultVO getBusinessIdByFoodName(String foodName) {
        QueryWrapper qw= new QueryWrapper();
        qw.eq("food_name",foodName);
        List<Food> foodList=foodMapper.selectList(qw);
        List<Business> businessList = new ArrayList<>();
        for(Food food:foodList){
            Integer businessId=food.getBusinessId();
            businessList.add(businessMapper.selectById(businessId));
        }
//            System.out.println(businessList);
        return ResultVO.ok("查询成功",businessList);
    }

    /**
     * 根据level编号查询食品列表
     *
     * @param
     * @return
     */
    @Override
    public ResultVO queryFoodByLevelId() {
        QueryWrapper qw = new QueryWrapper();
        qw.orderByAsc("level_id");
        List<Business> foodEntities = foodMapper.selectList(qw);
        return ResultVO.ok("查询成功", foodEntities);
    }

}
